package com.newlink.building.userinfo.mvp

import com.newlink.building.common_base.base.BasePresenter
import com.newlink.building.common_base.ext.ss
import com.newlink.building.common_base.model.bean.Base_AddFamilyManagementBean
import com.newlink.building.common_base.utils.logDebug
import com.newlink.building.userinfo.mvp.contract.Module_UserInfo_FamilyManagementAddContract
import com.newlink.building.userinfo.mvp.model.Module_UserInfo_FamilyManagementAddModel

/**
 * @author wangyang
 * @date 2022/10/11
 * @description 我的——家庭管理——添加家庭成员页面的Presenter
 */
class Module_UserInfo_FamilyManagementAddPresenter :
    BasePresenter<Module_UserInfo_FamilyManagementAddContract.Model, Module_UserInfo_FamilyManagementAddContract.View>(),
    Module_UserInfo_FamilyManagementAddContract.Presenter {

    override fun createModel(): Module_UserInfo_FamilyManagementAddContract.Model? {
        return Module_UserInfo_FamilyManagementAddModel()
    }

    override fun addFamilyManagement(
        token: String,
        addFamilyManagementBean: Base_AddFamilyManagementBean,
        serverType: Int
    ) {

        mModel?.addFamilyManagement(token, addFamilyManagementBean)?.ss(mModel, mView) {
            logDebug<Module_UserInfo_FamilyManagementAddPresenter>("[jake] serverType == 0 addFamilyManagement response ->  ${it?.data}")
            if (it?.data == null) {
                mView?.addFamilyManagementFail()
            } else {
                mView?.addFamilyManagementSuccess(it.data)
            }
        }
    }

    override fun updateEmail(token: String, userId: Long, email: String) {
        mModel?.updateEmail(token, userId, email)?.ss(mModel, mView) {
            logDebug<Module_UserInfo_FamilyManagementAddPresenter>("[jake] updateEmail response ->  ${it?.data}")
            mView?.updateEmailSuccess(it?.code == 200, email)
        }
    }

}